<div class="layui-container" style="padding: 5%">
    <div class="layui-row">
        <div class="layui-col-lg8 layui-col-lg-offset2">
            <form class="layui-form" id="student-form">
                <div class="layui-form-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">班级号</label>
                        <div class="layui-input-block">
                            <input type="text" name="claId" autocomplete="off" lay-verify="claId" placeholder="请输入班级号"
                                   class="layui-input">
                        </div>
                    </div>
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" autocomplete="off" lay-verify="name" placeholder="请输入姓名"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">单选框</label>
                    <div class="layui-input-block">
                        <input type="radio" name="gender" value="0" title="男" lay-verify="gender"
                               checked="">
                        <input type="radio" name="gender" value="1" title="女" lay-verify="gender">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">手机</label>
                        <div class="layui-input-inline">
                            <input type="text" name="phone" lay-verify="phone" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>

                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">邮箱</label>
                        <div class="layui-input-inline">
                            <input type="text" name="email" lay-verify="email" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn" lay-submit lay-filter="demo1" id="sub-btn">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer;
        form.render();
        form.on('radio', function () {
            form.render('radio');
        })

        form.verify({
            claId: function (value) {
                if (value.length < 1) {
                    return '班级号不能为空！';
                }
            },
            name: function (value) {
                if (value.length < 1) {
                    return '姓名不能为空';
                }
            },
            collegeId: function (value) {
                if (value.length < 1) {
                    return '请选择学院!';
                }
            },
            systemId: function (value) {
                if (value.length < 1) {
                    return '请选择系!';
                }
            }
        });
        //监听提交
        form.on('submit(demo1)', function (data) {
            // submit 提交事件
            let serialize = $("#student-form").serialize();
            $.ajax({
                url: "/student/add",
                type: "POST",
                data: serialize,
                dataType: "JSON",
                success: function (JSONResult) {
                    if (JSONResult.code === 0) {
                        layer.msg("添加完成！");
                    } else {
                        layer.msg("添加失败！");
                    }
                }
            });
            return false;
        });
    })

</script>